package zhaolu.com.example.Delicacy.Activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

import zhaolu.com.example.Delicacy.Entity.HistoryBean;
import zhaolu.com.example.Delicacy.Entity.ItemBean;
import zhaolu.com.example.Delicacy.MySQL.DishDAO;
import zhaolu.com.example.Delicacy.R;
import zhaolu.com.example.Delicacy.Utils.HistoryAdapter;

public class OrderHistory extends AppCompatActivity {
    private ListView listView;
    private List<HistoryBean> beanList;
    private DishDAO dishDAO;
    private HistoryAdapter historyAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.order_history);
        listView = findViewById(R.id.historyList);
        dishDAO = new DishDAO();
        beanList = new ArrayList<>();
        SharedPreferences sp = getSharedPreferences("login", Context.MODE_PRIVATE);
        String phone = sp.getString("username", null);
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                beanList = dishDAO.getHistoryBeanList(phone);
            }
        });
        thread.start();
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        historyAdapter = new HistoryAdapter(this, beanList);
        listView.setAdapter(historyAdapter);
    }
}
